#include<bits/stdc++.h>
using namespace std;
long long sum=0;
int n,x;
int main() {
	cin >> n >> x;
	long long a[n+1];
	cin >> a[1];
	if(a[1] > x) {
		sum += a[1] - x;
		a[1] = x;
	}
	for(int i = 2;i <= n;i++) {
		cin >> a[i];
		if(a[i] + a[i-1] > x) { 
			sum += a[i] + a[i-1] - x;
			a[i] = x - a[i-1];
		}
	}
	cout << sum;
	return 0;
}

